home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#29 (Feb 88)
/
Rotate Source Code
/
rot4Edit ƒ
/
rot4Edit.p
< prev
next >
Wrap
Text File
|
1988-01-02
|
4KB
|
161 lines
PROGRAM rot4Edit;
{
••••••••••••••••••••••••••••••••••
rot2Edit by John D. Olsen
idea by Scott Boyd, Greg Marriott
and John Olsen
for
MacTutor Magazine
© Jan 1988
••••••••••••••••••••••••••••••••••
}
uses
{$LOAD pinterfaces.dump}
MemTypes,QuickDraw,OsIntf,PasLibIntf,
ToolIntf,PackIntf,IntEnv,CursorCtl;
type
integerPtr = ^INTEGER;
var
item: Handle;
itemHit, invertItem : INTEGER;
map1, map2, map3, map4 : bitMap;
rect1, rect2, rect3, rect4 : rect;
FUNCTION NewPtrClear( theSize: size ) : Ptr; EXTERNAL;
PROCEDURE Rotate( srcMap, destMap : BitMap ); EXTERNAL;
PROCEDURE NewBitMapClear( VAR theBitMap : BitMap );
BEGIN
WITH theBitMap, bounds DO
BEGIN
rowBytes := ((right - left + 15) DIV 16) * 2;
baseAddr := NewPtrClear(rowBytes * (bottom - top));
IF MemError <> noErr then baseAddr := NIL;
END;
END;
FUNCTION filterProc(theDialog: DialogPtr; VAR theEvent: EventRecord; VAR itemHit: INTEGER): BOOLEAN;
CONST
EnterKey = $03;
BackspaceKey = $08;
TabKey = $09;
ReturnKey = $0D;
ClearKey = $1B;
DeleteKey = $7F;
{bits of the event modifiers long word}
CommandBit = 8;
VAR
itemNum: INTEGER;
kind: INTEGER;
box: Rect;
charCode: INTEGER;
theChar: Char;
dialog: DialogPtr;
VAR
noteDialog : DialogPtr;
itemType : integer;
BEGIN
filterProc := FALSE;
CASE theEvent.what OF
nullEvent:
BEGIN { 2, 3, 4, 5 }
GetDItem(theDialog, 2, kind, item, box);
GetDItem(theDialog, 3, kind, item, rect2);
GetDItem(theDialog, 4, kind, item, rect3);
GetDItem(theDialog, 5, kind, item, rect4);
CopyBits( thePort^.portBits, map1, box, map1.bounds, srcCopy, nil);
Rotate( map1, map2 );
Rotate( map2, map3 );
Rotate( map3, map4 );
CopyBits( map2, thePort^.portBits, map2.bounds, rect2, srcCopy, nil);
CopyBits( map3, thePort^.portBits, map3.bounds, rect3, srcCopy, nil);
CopyBits( map4, thePort^.portBits, map4.bounds, rect4, srcCopy, nil);
DisposPtr( map2.baseAddr );
DisposPtr( map3.baseAddr );
DisposPtr( map4.baseAddr );
END;
keyDown, autoKey:
BEGIN
charCode := BAND(theEvent.message, charCodeMask);
IF charCode IN [EnterKey] THEN
BEGIN
itemHit := 1;
filterProc := true;
EXIT(filterProc);
END;
IF charCode IN [ClearKey] THEN
BEGIN
IF theEvent.what = keyDown THEN DlgDelete(theDialog);
theEvent.what := nullEvent;
EXIT(filterProc)
END;
IF BTST(theEvent.modifiers, CommandBit) THEN
BEGIN
theChar := CHR(charCode);
CASE theChar OF
'X','x': IF theEvent.what = keyDown THEN DlgCut(theDialog);
'C','c': IF theEvent.what = keyDown THEN DlgCopy(theDialog);
'V','v': IF theEvent.what = keyDown THEN DlgPaste(theDialog);
OTHERWISE ;
END;
theEvent.what := nullEvent;
EXIT(filterProc);
END;
END;
END;
END;
PROCEDURE EditThatSucker;
type
strHandle = ^strPtr;
strPtr = ^Str255;
var
noteDialog : DialogPtr;
itemType : integer;
item : handle;
box : rect;
BEGIN
{Bring up the window}
noteDialog := GetNewDialog( 1000, NIL, windowPtr(-1) );
showWindow(noteDialog);
SetPort(noteDialog);
getDItem(noteDialog, 2, itemType, item, box);
map1.bounds := box;
NewBitMapClear( map1 );
InitCursor;
repeat
ModalDialog(@filterProc, itemHit);
until itemHit = 1;
DisposDialog(noteDialog);
END;{EditThatSucker}
BEGIN {main}
InitGraf(@thePort);
BEGIN
InitFonts;
InitWindows;
InitMenus;
TEInit;
InitDialogs(nil);
END;
invertItem := 1;
EditThatSucker;
END.